<?php 
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";

//'----
//'Ingresa aqui cuando da submit en la forma para modificar o eliminar definitivo
//'----
//'rw"",Request("opc")
//'re
if ($_REQUEST["hidId1"]!="") {

    switch ($_REQUEST["opc"]) {

//         '===============================
//         'MODIFICAR
//         '===============================
        case "M":

            $Combo1=$_REQUEST["hidId1"];
            $Combo2=$_REQUEST["hidId2"];
            $Combo3=$_REQUEST["hidId3"];
            $Combo4=$_REQUEST["hidId4"];

            $strSql="update solotb_nivel5 set ";
            $strSql .= "des='"  . ($_REQUEST["newds4"]) . "' ";
            $strSql .= "where id4=" . $_REQUEST["hidId4"];
            $strSql .= "  and id5=" . $_REQUEST["hidId5"];

            if ($_REQUEST["dsniv4"]==$_REQUEST["newds4"]) {
                header("Location: trn_SubCategorias3.php?SoloError=0&CmbModulo=$Combo1&CmbCategoria=$Combo2&CmbSubCategoria=$Combo3&CmbSubCategoria2=$Combo4&opc=3");
            }


//               'ruta=server.MapPath("/documentacion") & "\" & Request("dsniv1") & "\" &  Request("dsniv2") & "\" &  Request("dsniv3") & "\" &  Request("dsniv4")

//'	           Set fso = Server.CreateObject("Scripting.FileSystemObject")
// '              Set f = fso.GetFolder(ruta)
//  '             f.Name=Request("newds4")
            if ($err!=0) {
                header ("Location: trn_SubCategorias3.php?SoloError=1&CmbModulo=$Combo1&CmbCategoria=$Combo2&CmbSubCategoria=$Combo3&CmbSubCategoria2=$Combo4&opc=3");
            }


//         '===============================
//         'ELIMINAR
//         '===============================
            break;
        case "E":

            $Combo1=$_REQUEST["hidId1"];
            $Combo2=$_REQUEST["hidId2"];
            $Combo3=$_REQUEST["hidId3"];
            $Combo4=$_REQUEST["hidId4"];

            $strSql="delete from solotb_nivel5";
            $strSql .= " where id4=" . $_REQUEST["hidId4"];
            $strSql .= "   and id5=" . $_REQUEST["hidId5"];
//echo $strSql;
//     '     ruta=server.MapPath("/documentacion") & "\" & Request("dsniv1") & "\" &  Request("dsniv2") & "\" &  Request("dsniv3") & "\" &  Request("dsniv4")

//'	      Set fso = CreateObject("Scripting.FileSystemObject")
// '         fso.DeleteFolder(ruta)   
            if ($err!=0) {
                header("Location: trn_SubCategorias3.php?SoloError=1&CmbModulo=$Combo1&CmbCategoria=$Combo2&CmbSubCategoria=$Combo3&CmbSubCategoria2=$Combo4&opc=3");
            }


//         '===============================
//         'INGRESAR
//         '===============================
            break;
        default:

            $strSql="insert into solotb_nivel5 values (";
            $strSql .= $_REQUEST["CmbSubCategoria2"] . ",";
            $strSql .= $_REQUEST["hidId1"] . ",'";
            $strSql .= $_REQUEST["ATxtDesc"] . "')";
//'		 rw "",(strSql)
//'re

//'         set Recordset1=Server.CreateObject("ADODB.Recordset")
// '        strSql2="Select des from tb_empresas where id1="& Request("CmbModulo")
//	'	 Recordset1.Open strSql2,Session("conn")
//     '    set Recordset2=Server.CreateObject("ADODB.Recordset")
//      '   strSql2="Select des from tb_empresas_categoria where id2="& Request("CmbCategoria")
//		' Recordset2.Open strSql2,Session("conn")
//'         set Recordset3=Server.CreateObject("ADODB.Recordset")
// '        strSql2="Select des from tb_categoria_subcategoria where id3="& Request("CmbSubCategoria")
//	'	 Recordset3.Open strSql2,Session("conn")
//		 	  	  		 
//     '    ruta=server.MapPath("/documentacion") & "\" & (Recordset1.Fields.Item("des").Value) & "\" & (Recordset2.Fields.Item("des").Value) & "\" & (Recordset3.Fields.Item("des").Value) & "\" & Request("ATxtDesc")
//		' Set fs = CreateObject("Scripting.FileSystemObject")
//         'fs.CreateFolder(ruta)
            if ($err!=0) {
//'            Recordset1.close
//'		    Recordset2.close
//'		    Recordset3.close
//'		    set recordset1 = nothing
//'		    set recordset2 = nothing
//'		    set recordset3 = nothing		 
                header("Location: trn_SubCategorias3.php?SoloError=1&CmbModulo=$Combo1&CmbCategoria=$Combo2&CmbSubCategoria=$Combo3&CmbSubCategoria2=$Combo4&opc=3");
            }
//'         Recordset1.close
//'		 Recordset2.close
//'		 Recordset3.close
//'		 set recordset1 = nothing
//'		 set recordset2 = nothing
//'		 set recordset3 = nothing		 		 

            $Combo1=$_REQUEST["CmbModulo"];
            $Combo2=$_REQUEST["CmbCategoria"];
            $Combo3=$_REQUEST["CmbSubCategoria"];
            $Combo4=$_REQUEST["CmbSubCategoria2"];
//'  rw"",Combo2
//'  re
            break;
    }

//'	 response.write strsql
//'	 response.end


    $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
            $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);

    if(!$oConexion->EjecutarQuery($strSql)) {
        echo $strSql;
        echo $oConexion->getErrorMessage();
        $strMsg="trn_SubCategorias3.php?SoloError=1&CmbModulo=$Combo1&CmbCategoria=$Combo2&CmbSubCategoria=$Combo3&CmbSubCategoria2=$Combo4&opc=3";
    }else {
        $strMsg="trn_SubCategorias3.php?SoloError=0&CmbModulo=$Combo1&CmbCategoria=$Combo2&CmbSubCategoria=$Combo3&CmbSubCategoria2=$Combo4&opc=3";
    }
    $oConexion->Cerrar();

    header("location: $strMsg");
//'	  response.write strMsg
//'	  response.end

}


//'-------------------------------------------
//'Ingresa aqui cuando la primera vez ingresa
//'-------------------------------------------

switch ($_REQUEST["opc"]) {
    case "M":
        $boton ="<input type='submit' name='CmdGrabar' value='Modificar' class='SoloStyle_Boton'>";
        $oculto="<input type='hidden' name='opc' value='M'>";
        $titulo="Modificaci&oacute;n de Categor&iacute;a 3";
        break;
    case "E":
        $boton ="<input type='submit' name='CmdGrabar' value='Eliminar' class='SoloStyle_Boton'>";
        $oculto="<input type='hidden' name='opc' value='E'>";
        $titulo="Eliminaci&oacute;n de Categor&iacute;a 3";
        break;

}


?>
<html>
    <head>
        <title>Documentacion</title>
        <link rel="stylesheet" href="SoloStyles/Solostyles.css" type="text/css">
    </head>

    <body topmargin=0 leftmargin=0>
        <!-- Include File="includes/trn_header.asp" -->
        <p align="center" class="SoloStyle_TituloPaginas"><?php echo $titulo;?></p>

        <form name="frmIngreso" action="trn_GrabaSubCategoria3.php" method="POST">

            <table border="0" width="70%" align="center">
                <tr>
                    <td class="SoloStyle_Etiqueta">Empresa</td>
                    <td class="SoloStyle_Texto">
                        <?php
                        $strSql="select * from solotb_nivel1 where id1=" . $_REQUEST["id1"];

                        $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
                                $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
                        $oConexion->EjecutarQuery($strSql);
//echo $strSql;
                        $res = $oConexion->getData();
                        $Des1 = $res[0]["des"];
                        $oConexion->Cerrar();
                        echo $Des1;
                        ?>
                        <input type="hidden" maxlenght="50" size="50" name="dsniv1" class="SoloStyle_Texto" value="<?php echo $Des1;?>">
                        <input type="hidden" maxlenght="50" size="50" name="hidId1" class="SoloStyle_Texto" value="<?php echo $_REQUEST["id1"];?>"></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta">Departamento</td>
                    <td class="SoloStyle_Texto">
                        <?php
                        $strSql="select * from solotb_nivel2 where id2=" . $_REQUEST["id2"];
                        $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
                                $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
                        $oConexion->EjecutarQuery($strSql);

                        $res =$oConexion->getData();
                        $Des2 = $res[0]["des"];
                        $oConexion->Cerrar();
                        echo $Des2;
                        ?>
                        <input type="hidden" maxlenght="50" size="50" name="dsniv2" class="SoloStyle_Texto" value="<?php echo $Des2?> ">
                        <input type="hidden" maxlenght="50" size="50" name="hidId2" class="SoloStyle_Texto" value="<?php echo $_REQUEST["id2"];?> "></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta">Categor&iacute;a</td>
                    <td class="SoloStyle_Texto">
                        <?php
                        $strSql="select * from solotb_nivel3 where id3=" . $_REQUEST["id3"];
                        $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
                                $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
                        $oConexion->EjecutarQuery($strSql);

                        $res = $oConexion->getData();
                        $Des3 = $res[0]["des"];
                        $oConexion->Cerrar();
                        echo $Des3;
                        ?>
                        <input type="hidden" maxlenght="50" size="50" name="dsniv3" class="SoloStyle_Texto" value="<?php echo $Des3;?>">
                        <input type="hidden" maxlenght="50" size="50" name="hidId3" class="SoloStyle_Texto" value="<?php echo $_REQUEST["id3"];?>"></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta">Categor&iacute;a 2</td>
                    <td class="SoloStyle_Texto">
                        <?php
                        $strSql="select * from solotb_nivel4 where id4=" . $_REQUEST["id4"];
//'response.Write(strSql)
//'response.End()
                        $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
                                $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
                        $oConexion->EjecutarQuery($strSql);

                        $res = $oConexion->getData();
                        $Des4 = $res[0]["des"];
                        $oConexion->Cerrar();
                        echo $Des4;
                        ?>
                        <input type="hidden" maxlenght="50" size="50" name="dsniv3" class="SoloStyle_Texto" value="<?php echo $Des4;?>">
                        <input name="hidId4" type="hidden" class="SoloStyle_Texto" id="hidId4" value="<?php echo $_REQUEST["id4"];?>" size="50" maxlenght="50"></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta">Categor&iacute;a 3</td>
                    <td class="SoloStyle_Texto">
                        <?php
                        $strSql="select * from solotb_nivel5 where id5=" . $_REQUEST["id5"];
                        $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
                                $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
                        $oConexion->EjecutarQuery($strSql);

                        $res = $oConexion->getData();
                        $Des5 = $res[0]["des"];
                        $oConexion->Cerrar();
                        ?>
                        <input type="text" maxlenght="50" size="50" name="newds4" class="SoloStyle_Texto" value="<?php echo $_REQUEST["ds5"];?>">
                        <input type="hidden" maxlenght="50" size="50" name="dsniv4" class="SoloStyle_Texto" value="<?php echo $_REQUEST["ds5"];?>">
                        <input type="hidden" maxlenght="50" size="50" name="hidId5" class="SoloStyle_Texto" value="<?php echo $_REQUEST["id5"];?>"></td>
                </tr>
            </table>
            <br><center><?php echo $boton;
echo $oculto?></center>
        </form>

    </body>
</html>